from flask import Flask
from .views import auth
from .views import api
from .views import index
from .views import admin
from .views import article
from .views import favorite
from .views import comment
from .views import ueditor
from .views import ucenter
from .views import memo
from app.extensions import db


def create_app():
    app = Flask(__name__)
    app.config.from_object('config.settings')
    # 注册蓝图
    app.register_blueprint(auth.au_bp)
    app.register_blueprint(api.api_bp)
    app.register_blueprint(index.in_bp)
    app.register_blueprint(admin.ad_bp)
    app.register_blueprint(article.ar_bp)
    app.register_blueprint(favorite.fa_bp)
    app.register_blueprint(comment.co_bp)
    app.register_blueprint(ueditor.ue_bp)
    app.register_blueprint(ucenter.uc_bp)
    app.register_blueprint(memo.me_bp)

    # 初始化sqlalchemy数据库对象,传入app,获得配置里的数据库连接信息
    db.init_app(app)

    # 注册过滤器
    # app.jinja_env.filters.update(mytruncate=mytruncate)
    return app
